package controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import xtgl.User;




import com.jfinal.core.Controller;

import com.jfinal.plugin.activerecord.Db;


public class ActController extends Controller {

	public void getMenuList() {	
		User user=(User)getSession().getAttribute("user");
		List dataList = Db.find("select r.role_id, privilege.privilege_name as name, privilege.uri, privilege.s_class, privilege.privilege_id as id, privilege.parent_id as pid from (select * from role_privilege where role_privilege.role_id='"+user.getInt("role_id")+"') as r left join privilege on r.privilege_id=privilege.privilege_id;");
		Map<String, Object> resp=new HashMap<String, Object>();
		resp.put("code", 0);
		resp.put("content", dataList);
		renderJson(resp);
	}
	
	public void mmpd(){							//修改密码时判断原密码是否正确
		User user=(User)getSession().getAttribute("user");
		if (user.getStr("password").equals(getPara("str")))
			renderText("true");
		else
			renderText("false");
	}
	
	public void uppass(){
		String password=getPara("password");
		User user=(User)getSession().getAttribute("user");
		User user2=User.dao.findById(user.getInt("id"));
		user2.set("password", password);
		user2.update();
		renderText("true");
	}
	
	public void getuser(){
		User user= (User) getSession().getAttribute("user");
		renderJson(user);
	}
	
}
